/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-06-29     Rbb666       first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#include <dfs_fs.h>

#include "drv_gpio.h"

#define LED_PIN     GET_PIN(0, 1)

int main(void)
{
    rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
    
    for(;;)
    {
        rt_device_t sd = rt_device_find("sd0");
        if(sd != RT_NULL)
        {
            if(dfs_mount("sd0", "/", "elm", 0, NULL) == 0)
            {
                break;
            }
        }
        rt_kprintf("mount sd0 try again...\r\n");
        rt_thread_mdelay(1000);
    }

    for (;;)
    {
        rt_pin_write(LED_PIN, PIN_HIGH);
        rt_thread_mdelay(500);
        rt_pin_write(LED_PIN, PIN_LOW);
        rt_thread_mdelay(500);
    }
}
static int iray_cam_cmd(int argc, char *argv[])
{
    if(argc > 2)
    {
        if(rt_strcmp(argv[1], "run") == 0)
        {
            void iray_camera_init(const char *bus);
            void ft6236_init(char *bus, int pin);
            int pin = 90;
            char *bus = argv[2];
            if(argc > 3)
            {
                pin = atoi(argv[3]);
            }
            ft6236_init(bus, pin);
            while(1)
            {
                rt_device_t tp = rt_device_find("tp");
                if(tp != NULL)
                {
                    break;
                }
                rt_thread_mdelay(100);
            }
            rt_thread_mdelay(200);
            iray_camera_init(bus);
            return RT_EOK; 
        }
    }
    rt_kprintf("usage: iray_cam run <i2c bus> <tp int>\r\n");
    return RT_EOK; 
}
//INIT_APP_EXPORT(rt_lvgl_demo_init); 
MSH_CMD_EXPORT_ALIAS(iray_cam_cmd, iray_cam,iray camera);
